package com.cuc.platform.core.componet.security.dao.jdbc;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import com.cuc.platform.core.componet.security.dao.SecurityAuthorityDao;
import com.cuc.platform.core.componet.security.domain.SecurityAuthority;

/**
 * @author peepul
 *
 */
@Repository("SecurityAuthorityDao")
public class SecurityAuthorityDaoImpl implements SecurityAuthorityDao {

	public SecurityAuthorityDaoImpl() {
		// TODO Auto-generated constructor stub
	}

	@Override
	public List<SecurityAuthority> getAllAuths() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public SecurityAuthority getAuthById(Long id) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public SecurityAuthority getAuthWithRescs(Long id) {
		// TODO Auto-generated method stub
		return null;
	}

	/* (non-Javadoc)
	 * @see com.cuc.platform.core.componet.security.dao.SecurityAuthorityDao#getAuthsByRoleId(java.lang.Long)
	 */
	@Override
	public List<SecurityAuthority> getAuthsByRoleId(Long roleId) {
	/*	select au.id, au.name, au.isadmin,  au.descn from ss_auth au , ss_role ro, ss_role_auth ra  
		where au.id=ra.auth_id 
		and ra.role_id = ro.id
		and ro.id = ? */
		
		StringBuffer sb = new StringBuffer();
		sb.append(" select au.id, au.name, au.isAdmin,  au.descn from ss_auth au , ss_role ro, ss_role_auth ra ");
		sb.append(" where au.id = ra.auth_id ");
		sb.append(" and ra.role_id = ro.id ");
		sb.append(" and ro.id = ? ");
		
		return jdbcTemplate.query(sb.toString(),  
				new Object[]{roleId}, new BeanPropertyRowMapper<SecurityAuthority>(SecurityAuthority.class) );
	}

	@Override
	public void insertAuth(SecurityAuthority auth) throws DataAccessException {
		// TODO Auto-generated method stub

	}

	@Override
	public void updateAuth(SecurityAuthority auth) throws DataAccessException {
		// TODO Auto-generated method stub

	}

	@Override
	public int delAuthById(Long id) throws DataAccessException {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public List<SecurityAuthority> viewRescswithAuths(Long authId) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void delAuthRescUnions(Long authId) throws DataAccessException {
		// TODO Auto-generated method stub

	}

	@Override
	public void saveAuthRescUnion(Map<String, Long> map) {
		// TODO Auto-generated method stub

	}
	
	/**
	 * Ioc
	 */
	@Resource
	private JdbcTemplate jdbcTemplate;
}
